/****************************************************************

this file is part of Music Practice Audio Player
Copyright (C)2012 Serhii Ratsyborynskyi (ratz@live.ru)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

******************************************************************/

#include "CPMpaPlayerController.hpp"

CPMpaPlayerController::CPMpaPlayerController(QWidget *parent): QWidget(parent),
                                                               mpFileDialog(new QFileDialog(this,
                                                                           "Open MPA File",
                                                                           "D:\\SourceCode\\mpaplayer\\trunk\\Misc\\mpaTest",
                                                                           "*.mpa"))
{
    initGrafics();
}

void CPMpaPlayerController::slotEnable(bool enable)
{
    emit signalEnabled(enable);
}

void CPMpaPlayerController::slotFileOpen()
{
    mpFileDialog->show();
}

void CPMpaPlayerController::initGrafics()
{
    QPushButton * pcmdOpen = new QPushButton("&Open", this);
    QPushButton * pcmdPlayPause = new QPushButton("&Play", this);
    QPushButton * pcmdStop = new QPushButton("&Stop", this);
    QSlider     * pSliderVolume = new QSlider(Qt::Horizontal, this);
    pSliderVolume->setValue(100);
    QLabel      * pLabel = new QLabel("Volume", this);

    QVBoxLayout * pvbxLayout = new QVBoxLayout;
    QHBoxLayout * phbxLayout = new QHBoxLayout;
    QHBoxLayout * phbxLayoutVolume = new QHBoxLayout;

    phbxLayout->addWidget(pcmdOpen);
    phbxLayout->addWidget(pcmdPlayPause);
    phbxLayout->addWidget(pcmdStop);

    phbxLayoutVolume->addWidget(pLabel);
    phbxLayoutVolume->addWidget(pSliderVolume);

    pvbxLayout->addLayout(phbxLayoutVolume);
    pvbxLayout->addLayout(phbxLayout);

    setLayout(pvbxLayout);
    // Disable by default
    pcmdPlayPause->setEnabled(false);
    pcmdStop->setEnabled(false);

    connect( this, SIGNAL(signalEnabled(bool)), pcmdPlayPause, SLOT(setEnabled(bool)) );
    connect( this, SIGNAL(signalEnabled(bool)), pcmdStop, SLOT(setEnabled(bool)) );
    connect( pcmdOpen, SIGNAL(clicked()), this, SLOT(slotFileOpen()) );
    // Connect play stop signals to signals
    connect( pcmdPlayPause, SIGNAL(clicked()), this, SIGNAL(signalPlay()));
    connect( pcmdStop, SIGNAL(clicked()), this, SIGNAL(signalStop()));
    connect( mpFileDialog, SIGNAL(fileSelected(QString)), this, SIGNAL(signalFileOpen(QString)));
    connect( pSliderVolume, SIGNAL(valueChanged(int)), this, SIGNAL(signalMainVolume(int)));
}
